package com.earthea.scaffold.common.validator;

import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class PasswordValidatorImplTest {

    @Test
    public void testValidPassword() {
        // 测试包含大小写字母、数字和特殊字符的有效密码
        String validPassword = "Pass123!";
        PasswordValidatorImpl passwordValidator = new PasswordValidatorImpl();
        assertTrue(passwordValidator.isValid(validPassword, null));
    }

    @Test
    public void testNullPassword() {
        // 测试null输入
        assertFalse(PasswordValidatorImpl.isValid(null));
    }

    @Test
    public void testEmptyPassword() {
        // 测试空字符串输入
        assertFalse(PasswordValidatorImpl.isValid(""));
    }

    @Test
    public void testBlankPassword() {
        // 测试空白字符串输入
        assertFalse(PasswordValidatorImpl.isValid("   "));
    }

    @Test
    public void testNoUpperCase() {
        // 测试缺少大写字母的密码
        String password = "pass123!";
        assertFalse(PasswordValidatorImpl.isValid(password));
    }

    @Test
    public void testNoLowerCase() {
        // 测试缺少小写字母的密码
        String password = "PASS123!";
        assertFalse(PasswordValidatorImpl.isValid(password));
    }

    @Test
    public void testNoNumber() {
        // 测试缺少数字的密码
        String password = "PassWord!";
        assertFalse(PasswordValidatorImpl.isValid(password));
    }

    @Test
    public void testNoSpecialChar() {
        // 测试缺少特殊字符的密码
        String password = "PassWord123";
        assertFalse(PasswordValidatorImpl.isValid(password));
    }

    @Test
    public void testAllSpecialChars() {
        // 测试只包含特殊字符的密码（应该失败）
        String password = "!@#$%^&*()";
        assertFalse(PasswordValidatorImpl.isValid(password));
    }

    @Test
    public void testOnlyNumbersAndLetters() {
        // 测试只有字母和数字的密码（应该失败）
        String password = "Password123";
        assertFalse(PasswordValidatorImpl.isValid(password));
    }
}